//
//  ProfileManuController.m
//  MathMasterMain
//
//  Created by Jimmy Hahm on 10-03-13.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "ProfileMenuController.h"
#import "ProfileCreationController.h"
#import "Profile.h"
#import "ProfileXMLParser.h"
#import "ProfileXMLWriter.h"
#import "SoundController.h"

@implementation ProfileMenuController
@synthesize profileCController;
@synthesize tempName;
-(void)loadProfiles
{ /*
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDirectory = [paths objectAtIndex:0];
	NSString *fileName = [NSString stringWithFormat:@"%@/profile.txt", documentsDirectory];
	NSString *content;
	if([[NSString alloc] initWithContentsOfFile:fileName usedEncoding:nil error:nil] != nil)
	{
		content = [[NSString alloc] initWithContentsOfFile:fileName usedEncoding:nil error:nil];
		//int index = [content rangeOfString:@"\n"].location;
		//if(index>1){
		[profile1 setTitle:content forState:UIControlStateNormal];
	//	}
		
		/*if(index> 0)
		{
			[profile2 setTitle:[content substringFromIndex:index + 1] forState:UIControlStateNormal];
		}
		[content release];
		//[paths release];
		//[documentsDirectory release];
		//[fileName release];
	}*/
	
}



//@synthesize profileCreationController;


/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
	ProfileXMLWriter *PXML = [ProfileXMLWriter new];
	[PXML startProfile];
	
	ProfileXMLParser* xmlParser = [ ProfileXMLParser new ];
	//NSURL* url = [ NSURL URLWithString: @"http://mathmasters.googlecode.com/svn/trunk/MathMasterMain/QDB.xml" ];
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDirectory = [paths objectAtIndex:0];
	NSString *appFile = [documentsDirectory stringByAppendingPathComponent:@"PROFILE.xml"];
	NSMutableArray* Q = [ xmlParser parseContentOfpath:appFile ];
	NSString *temp1 = [[Q objectAtIndex:0] name];
	if(temp1 != nil){
		[profile1 setTitle:temp1 forState:UIControlStateNormal];
	}
	NSString *temp2 = [[Q objectAtIndex:1] name];
	if(temp2 != nil){
		[profile2 setTitle:temp2 forState:UIControlStateNormal];
	}
	NSString *temp3 = [[Q objectAtIndex:2] name];
	if(temp3 != nil){
		[profile3 setTitle:temp3 forState:UIControlStateNormal];
	}
	NSString *temp4 = [[Q objectAtIndex:3] name];
	if(temp4 != nil){
		[profile4 setTitle:temp4 forState:UIControlStateNormal];
	}

	[PXML release];
	[xmlParser release];
	[Q removeAllObjects];
	[temp1 release];
	[temp2 release];
	[temp3 release];
	[temp4 release];
	
    [super viewDidLoad];
}



-(IBAction)dissmissSelf:(id)sender{
	tempName = [sender currentTitle];
	[self dismissModalViewControllerAnimated:YES];
	
	
}


-(void)reload
{
	
	ProfileXMLParser* xmlParser2 = [ ProfileXMLParser new ];
	//NSURL* url = [ NSURL URLWithString: @"http://mathmasters.googlecode.com/svn/trunk/MathMasterMain/QDB.xml" ];
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDirectory = [paths objectAtIndex:0];
	NSString *appFile = [documentsDirectory stringByAppendingPathComponent:@"PROFILE.xml"];
	NSMutableArray* Q = [ xmlParser2 parseContentOfpath:appFile ];
	NSString *temp1 = [[Q objectAtIndex:0] name];
	if(temp1 != nil){
		[profile1 setTitle:temp1 forState:UIControlStateNormal];
	}
	NSString *temp2 = [[Q objectAtIndex:1] name];
	if(temp2 != nil){
		[profile2 setTitle:temp2 forState:UIControlStateNormal];
	}
	NSString *temp3 = [[Q objectAtIndex:2] name];
	if(temp3 != nil){
		[profile3 setTitle:temp3 forState:UIControlStateNormal];
	}
	NSString *temp4 = [[Q objectAtIndex:3] name];
	if(temp4 != nil){
		[profile4 setTitle:temp4 forState:UIControlStateNormal];
	}
	[xmlParser2 release];
	[Q removeAllObjects];
	[temp1 release];
	[temp2 release];
	[temp3 release];
	[temp4 release];
}


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

//- (IBAction)openAdminMenu:(id)sender {
	
	
	
	
//}

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end
